//
//  BillCell2.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/9/6.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "BillCell2.h"
@interface BillCell2()

@property(nonatomic,strong)UIView * line;

@property(nonatomic,strong)UILabel * mainTitleLabel;

@property(nonatomic,strong)UILabel * dateLabel;

@property(nonatomic,strong)UILabel * detailLabel;
@end
@implementation BillCell2

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.cellHeight = Bill_height(50);
        UIImageView * backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(globalMargin, 0, ScreenWidth-2*globalMargin, self.cellHeight)];
        [self.contentView insertSubview:backgroundImageView atIndex:0];
        self.backgroundImageView = backgroundImageView;
        UIView * line = [[UIView alloc] initWithFrame:CGRectMake(2*globalMargin, self.cellHeight - 1, ScreenWidth-4*globalMargin, 1)];
        line.backgroundColor =HexColor(@"#EEEEEE");
        [self.contentView addSubview:line];
        self.line = line;
        self.enableUnderLine = NO;
        
        self.mainTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.mainTitleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.mainTitleLabel];
        
        self.dateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.dateLabel.font = [UIFont systemFontOfSize:11];
        self.dateLabel.textColor = HexColor(@"#999999");
        [self.contentView addSubview:self.dateLabel];
        
        self.detailLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.detailLabel.font = [UIFont systemFontOfSize:24];
        [self.contentView addSubview:self.detailLabel];
        //HexColor(@"#3CB034");
        //HexColor(@"#F0A228");
        

    }
    return self;
}


-(void)setBackgroundImage:(UIImage *)backgroundImage{
    _backgroundImage = backgroundImage;
    self.backgroundImageView.image = _backgroundImage;
    [self setNeedsLayout];
}


-(void)setEnableUnderLine:(BOOL)enableUnderLine{
    _enableUnderLine = enableUnderLine;
    self.line.hidden = !_enableUnderLine;
}


-(void)setMaintitle:(NSString*)mainTitle date:(NSString*)date detail:(CGFloat)detail{
    self.mainTitleLabel.text = mainTitle;
    self.dateLabel.text = date;
    self.detailLabel.text = [NSString stringWithFormat:@"%.2f",detail];
    if(detail>=0){
     self.detailLabel.textColor = HexColor(@"#3CB034");
     self.detailLabel.text = [self.detailLabel.text addHeader:@"+"];
    }
    else{
        
        self.detailLabel.textColor = HexColor(@"#F0A228");
    }
    [self setNeedsLayout];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.line.size = CGSizeMake(ScreenWidth-4*globalMargin, 0.5);
    self.line.x = 2*globalMargin;
    self.line.y = self.cellHeight;
    
    self.mainTitleLabel.size = [self.mainTitleLabel.text sizeInAre:MaxSize font:self.mainTitleLabel.font];
    self.mainTitleLabel.x = 2*globalMargin;
    self.mainTitleLabel.y = globalMargin;
    
    self.dateLabel.size = [self.dateLabel.text sizeInAre:MaxSize font:self.dateLabel.font];
    self.dateLabel.x = self.mainTitleLabel.x;
    self.dateLabel.y = self.mainTitleLabel.botton + 5;
    
    self.detailLabel.size = [self.detailLabel.text sizeInAre:MaxSize font:self.detailLabel.font];
    self.detailLabel.x = ScreenWidth - self.detailLabel.width-2*globalMargin;
    self.detailLabel.centerY = self.cellHeight*0.5;
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
}
@end
